{extend name="base" /}
<!-- page specific plugin styles -->
{block name="inline-styles"}
{/block}
<!-- PAGE CONTENT BEGINS -->
{block name="content"}
<div class="page js_show">
    <div class="page__bd" id="ajaxForm">

        <div class="weui-panel">
            <div class="weui-panel__hd weui-flex">
                <div class="weui-flex__item">订单号：<span id="oid"></span></div>
                <p id="paytime"></p>
            </div>
            <div class="weui-panel__bd">
                <div class="weui-cell">
                    <div class="weui-cell__bd">
                        <p>收货人：<span id="receive_name"></span></p>
                        <p>联系电话：<span id="receive_tel"></span></p>
                        <p>收货地址：<span id="addr"></span></p>
                    </div>
                    <div class="weui-cell__ft">
                        <span class="weui-wepay-color-lightblue" id="ispay">待发货</span>
                    </div>
                </div>
                <div class="weui-media-box weui-media-box_appmsg" style="background-color: #fafafa">
                    <div class="weui-media-box__hd">
                        <img class="weui-media-box__thumb" id = "pic" src="" alt="">
                    </div>
                    <div class="weui-media-box__bd">
                        <h4 class="weui-media-box__title" id="goodsname"></h4>
                        <p class="weui-media-box__desc" >￥<span id="sigprice">29.90</span></p>
                    </div>
                    <div class="weui-media-box__ft">
                        <p>x <span id="courier_num">1</span></p>
                    </div>
                </div>
            </div>
            <div class="weui-panel__ft">
                <div class="weui-cell">
                    <div class="weui-cell__bd">共<span id="courier_num">1</span>件商品</div>
                    <div class="weui-cell__ft">
                        <p class="weui-wepay-color-red">合计:￥<span id="total">29.90</span></p>
                    </div>
                </div>
            </div>
        </div>

        <div class="weui-panel">
            <div class="weui-panel__bd">
                <div class="weui-media-box weui-media-box_appmsg">
                    <div class="weui-media-box__bd">
                        <h4 class="weui-media-box__title">物流信息</h4>
                        <p class="weui-media-box__desc">物流公司：<span id='express_name'></span></p>
                        <p class="weui-media-box__desc">物流单号：<span id='express_no'></span></p>
                    </div>
                    <div class="weui-media-box__ft">
                        <a class="weui-wepay-color-lightblue" target="_blank" href="" id='express'>查看物流</a>
                    </div>
                </div>
                <div class="weui-cell">
                    <div class="weui-cell__bd">
                        <span>规格:
                            <span class="weui-media-box__desc" id="key_name"></span>
                        </span>
                    </div>
                </div>
                <div class="weui-cell">
                    <div class="weui-cell__bd">
                        <h4>备注信息:</h4>
                        <p class="weui-media-box__desc" id="beizhu"></p>
                    </div>
                </div>
            </div>
        </div>
        <div class="weui-btn-area" id='cancel_order' style="margin-left: 60px;margin-right: 60px;">
            
        </div>
        <div class="weui-btn-area" id='confirm' style="margin-left: 60px;margin-right: 60px;">
            
        </div>
        <div class="weui-btn-area" style="margin-left: 60px;margin-right: 60px;">
            <a class="weui-btn weui-btn_primary" href="{:url('Index/goods')}">继续购买</a>
        </div>
        <div class="weui-tabbar">
                <a href="{:url('Index/home')}" class="weui-tabbar__item">
                    <div class="weui-tabbar__icon">
                        <i class="fa fa-home"></i>
                    </div>
                    <p class="weui-tabbar__label">主页</p>
                </a>
                <a href="{:url('Index/order')}" class="weui-tabbar__item">
                    <div class="weui-tabbar__icon">
                        <i class="fa fa-list"></i>
                    </div>
                    <p class="weui-tabbar__label">我的订单</p>
                </a>
        </div>
    </div>
</div>
{/block}
<!-- PAGE CONTENT ENDS -->
<!-- inline scripts related to this page -->
{block name="related-scripts"}
<script type="text/javascript">
    $.ajax({
        url: '/api/v1/goodsorder/find',
        type: 'GET',
        dataType: 'json',
        data:{
            id: GetQueryString("id")
        }
    })
    .done(function(json) {
        console.log("success");
        initPageHTML("ajaxForm",json.data);
        href = 'https://m.kuaidi100.com/index_all.html?type=&postid='+json.data.express_no;
        $('#express').attr('href',href);
        $('#pic').attr('src',json.data.pic);
        if(json.data.can_cancel){
        	$('#cancel_order').html('<a class="weui-btn weui-btn_warn" href="javascript:;" onclick="orderCancel()">取消订单</a>');
        }
        if(json.data.status == 3){
        	$('#confirm').html('<a class="weui-btn weui-btn_primary" href="javascript:;" onclick="confirm_received()">确认收货</a>');	
        }
        $('#addr').html(json.data.receive_addrvalue+' '+ json.data.receive_addr);
        
    })
    .fail(function() {
        console.log("error");
    })
    .always(function() {
        console.log("complete");
    });

    // 取消订单
    function orderCancel() {
        // body...
        $.ajax({
            url: '/api/v1/goodsorder/cancel',
            type: 'POST',
            dataType: 'json',
            data: {id: GetQueryString("id")},
        })
        .done(function(json) {
            if(json.returnCode==1){
                $.toast("取消成功");
                location.reload();
            }else{
                $.toptip(json.returnMsg, 'error');
            }
        })
        .fail(function() {
            console.log("error");
        })
        .always(function() {
            console.log("complete");
        });
    }
    
    function confirm_received(){
        res = confirm('您确认已经收到货了吗?')
        if(!res){
            return false;
        }
        // body...
        $.ajax({
            url: '/api/v1/goodsorder/confirm',
            type: 'POST',
            dataType: 'json',
            data: {id: GetQueryString("id")},
        })
        .done(function(json) {
            if(json.returnCode==1){
                $.toast("确认成功");
                location.reload();
            }else{
                $.toptip(json.returnMsg, 'error');
            }
        })
        .fail(function() {
            console.log("error");
        })
        .always(function() {
            console.log("complete");
        });
    }

//重置浏览器回退链接
browserBack("order.html");
</script>
{/block}